home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
combox.exe
/
COMBODEM.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1992-12-24
|
4KB
|
173 lines
Program ComboDemo;
uses App, Objects, Drivers, Memory, Views, Menus, Dialogs,
StdDlg, MsgBox, Combo;
{ This is a do-nothing application to demonstrate the use of the
combo box in Turbo Vision. }
const
cmShowDialog = 1000;
type
PNameEntry = ^TNameEntry;
TNameEntry = object(TObject)
Name : PString;
constructor Init(NewName : string);
destructor Done; virtual;
end;
PNameList = ^TNameList;
TNameList = object(TComboCollection)
function TxtPtr(Item : integer) : String; virtual;
function KeyOf(Item: Pointer): Pointer; virtual;
function Compare(Key1, Key2: Pointer): Integer; virtual;
end;
TDemo = object(TApplication)
NameList : PNameList;
constructor Init;
destructor Done; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure InitMenuBar; virtual;
procedure InitStatusLine; virtual;
end;
constructor TNameEntry.Init;
begin
TObject.Init;
Name := NewStr(NewName);
end;
destructor TNameEntry.Done;
begin
DisposeStr(Name);
TObject.Done;
end;
{This function is required. You MUST override this function in order
to send the ComboBox a string to display corresponding to Item.}
function TNameList.TxtPtr;
begin
TxtPtr := PNameEntry(At(Item))^.Name^;
end;
function TNameList.KeyOf;
begin
KeyOf := PNameEntry(Item)^.Name;
end;
function TNameList.Compare;
begin
if PString(Key1)^ < PString(Key2)^ then Compare := -1 else
if PString(Key1)^ = PString(Key2)^ then Compare := 0 else
if PString(Key1)^ > PString(Key2)^ then Compare := 1;
end;
constructor TDemo.Init;
begin
TApplication.Init;
InitMenuBar;
InitStatusLine;
{Make a list and stick some stuff in it.}
NameList := New(PNameList, Init(10,5));
with NameList^ do
begin
Insert(New(PNameEntry, Init('GREER, KEITH')));
Insert(New(PNameEntry, Init('WRIGHT, WILBUR')));
Insert(New(PNameEntry, Init('BUSH, GEORGE')));
Insert(New(PNameEntry, Init('CLINTON, BILL')));
Insert(New(PNameEntry, Init('PEROT, ROSS')));
Insert(New(PNameEntry, Init('EARP, WYATT')));
Insert(New(PNameEntry, Init('PRESLEY, PRISCILLA')));
Insert(New(PNameEntry, Init('ASPIN, LES')));
Insert(New(PNameEntry, Init('KENNEDY, GEORGE')));
Insert(New(PNameEntry, Init('DONALDSON, SAM')));
end;
end;
procedure TDemo.InitMenuBar;
var
R: TRect;
begin
GetExtent(R);
R.B.Y := R.A.Y+1;
MenuBar := New(PMenuBar, Init(R, NewMenu(
NewSubMenu('~F~ile', hcNoContext, NewMenu(
NewItem('~D~emo Dialog','', kbNoKey, cmShowDialog, hcNoContext,
NewLine(
NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext, nil)))),
nil))));
end;
procedure TDemo.InitStatusLine;
var
R: TRect;
begin
GetExtent(R);
R.A.Y := R.B.Y - 1;
StatusLine := New(PStatusLine, Init(R,
NewStatusDef(0, 4,
NewStatusKey('~F2~ Show Demo Dialog', kbF2, cmShowDialog,
NewStatusKey('~F10~ Menu', kbF10, cmMenu,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
nil))),
nil)));
end;
procedure TDemo.HandleEvent;
procedure ShowDialog;
var
Bounds, R : TRect;
D : PDialog;
B : pointer;
begin
Bounds.Assign(0,0,45,10);
D := New(PDialog, Init(Bounds, 'Combo Box Demo'));
with D^ do
begin
Options := Options or ofCentered;
R.Assign(2,3,37,4);
B := New(PInputLine, Init(R, 35));
R.Assign(37,3,40,4);
Insert(B);
Insert(New(PComboBox, Init(R, B, NameList)));
R.Assign(2,2,37,3);
Insert(New(PLabel, Init(R, 'Sample Input Line', B)));
end;
DeskTop^.ExecView(D);
Dispose(D, Done);
end;
begin {TDemo.HandleEvent}
TApplication.HandleEvent(Event);
case Event.What of
evCommand:
begin
case Event.Command of
cmShowDialog : ShowDialog;
else
Exit;
end;
ClearEvent(Event);
end;
end;
end;
destructor TDemo.Done;
begin
Dispose(NameList,Done);
TApplication.Done;
WriteLn('Have fun with TComboBox!');
end;
var
Demo : TDemo;
begin
Demo.Init;
Demo.Run;
Demo.Done;
end.